/**
 * 
 */
package ar.edu.unicen.exa.oop.bbquery.model.forum.content.filters;

import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;

import ar.edu.unicen.exa.oop.bbquery.model.forum.content.PostContent;

/**
 * @author nicolas
 *
 */
public class CompositeContentFilter extends LinkedList<ContentFilter> implements ContentFilter {

    /**
     * AND Operator is the default operator ... 
     * 
     */
    public CompositeContentFilter() {
	super();
	this.Operator=LogicalOperation.AND;	
    }

    /**
     * @param c a collection of classes from ContentFilter hierarchy
     */
    public CompositeContentFilter(Collection<? extends ContentFilter> c) {
	super(c);
	this.Operator=LogicalOperation.AND;	
    }

    private static final long serialVersionUID = 1L;
    
    LogicalOperation Operator;
    
    @Override
    public boolean evaluate(PostContent thing) {
	boolean value = Operator.getLeftNeutralValue();
	for (Iterator<ContentFilter> iterator = this.iterator(); iterator.hasNext();) {
	    ContentFilter type = iterator.next();
	    value= Operator.calculate(value, type.evaluate(thing));
	}
	return value;
    }
    
    public CompositeContentFilter(LogicalOperation op) {
	this.Operator=op;
    }

}
